package com.ruoyi.api.controller;

import com.ruoyi.anan.util.ZhihesjUtil;
import com.ruoyi.api.service.SelectService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.datamanagement.domain.SysDataSearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anan.
 * @version 1.0
 * @create 2021-04-08 11-59
 */
@RestController
@RequestMapping("/api")
public class SelectController {

    @Autowired
    private SelectService selectService;

    /**
     * 查询管理
     * @param map
     * @return
     */
    @GetMapping("/selectMethod")
	public AjaxResult selectMethod(@RequestParam Map map){
		String method = (String) map.get("method");
		SysDataSearch dataSearch = new SysDataSearch();
		List list1 = new ArrayList();
		if (method!=null && !method.isEmpty()) {
			/** 获取查询语句 */
			dataSearch = selectService.getDataSourceByMethod(method);
			/** 根据查询语句获取结果 */
			List list = selectService.getData(dataSearch,map);
			/** 将后面获取的list转换成驼峰list */
			list1 = ZhihesjUtil.getConResults(list);
		}
		return AjaxResult.success(list1);
	}

	@GetMapping("/method")
	public AjaxResult method(@RequestParam Map map){
		String method = (String) map.get("method");
		SysDataSearch dataSearch = new SysDataSearch();
		List list1 = new ArrayList();
		if (method!=null && !method.isEmpty()) {
			/** 获取查询语句 */
			dataSearch = selectService.getDataSourceByMethod(method);
			/** 根据查询语句获取结果 */
			List list = selectService.getData(dataSearch,map);
			/** 将后面获取的list转换成驼峰list */
			list1 = ZhihesjUtil.getConResults(list);
		}
		return AjaxResult.success(list1);
	}
}
